﻿using System.Runtime.InteropServices;

namespace U8DllPack.Controller
{
    internal partial class CommFun
    {
        // <summary>
        /// 返回Guid
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        [LibraryImport("rpcrt4.dll", SetLastError = true)]
        private static partial int UuidCreateSequential(out Guid guid);
        /// <summary>
        /// 生成顺序全球唯一码
        /// </summary>
        /// <returns></returns>
        public static Guid NewSequentialid()
        {
            const int RPC_S_OK = 0;
            int result = UuidCreateSequential(out Guid guid);
            if (result != RPC_S_OK)
            {
                throw new ApplicationException("创建顺序Guid失败：" + result);
            }
            return guid;
        }
        /// <summary>
        /// 通用消息框
        /// </summary>
        /// <param name="Msg">消息</param>
        /// <param name="SW">开关：0提示，1警告，2询问：是否，3询问：确定取消</param>
        /// <returns></returns>
        internal static DialogResult MsgBox(string Msg, int SW = 0)
        {
            DialogResult result = DialogResult.None;
            switch (SW)
            {
                case 0:
                    result = MessageBox.Show(Msg, "提示！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    break;
                case 1:
                    result = MessageBox.Show(Msg, "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    break;
                case 2:
                    result = MessageBox.Show(Msg, "询问？", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    break;
                case 3:
                    result = MessageBox.Show(Msg, "询问？", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    break;
            }
            return result;
        }
    }
}
